package com.qh.resourcehub.info.virtualresource.service.impl;

import com.qh.resourcehub.info.entity.ApplicationData;
import com.qh.resourcehub.info.virtualresource.dao.VmApplicationDao;
import com.qh.resourcehub.info.virtualresource.service.VmApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;


@Service
public class VmApplicationServiceImpl implements VmApplicationService {


    @Autowired
    VmApplicationDao vmApplicationDao;
    @Override
    public List<Map<String, Object>> queryVmDataService(ApplicationData applicationData) {
        //按照当前传用户id（必传）
        if (!StringUtils.isEmpty(applicationData.getApplyUser())){
            return vmApplicationDao.queryVmDataService(applicationData);
        }else {
            return Collections.emptyList();
        }
    }

    @Override
    public int ApplicationRequestByVm(ApplicationData applicationData) {
        int result = 0;
        if (!StringUtils.isEmpty(applicationData.getApplyUser())){
            //判断当前是保存还是提交
            return result;
        }else {
            return result;
        }
    }

    /**
     * IP新增
     * @param applicationData
     * @return
     */
    @Override
    public int ApplicationSave(ApplicationData applicationData) {
        int result = 0;
        //设置状态
        applicationData.setProcessStatus("00");//未提交
        //类型
        applicationData.setDataType("1");
        //设置申请时间
        applicationData.setApplicationTime(LocalDateTime.now());
        if (!StringUtils.isEmpty(applicationData.getApplyUser()) && StringUtils.isEmpty(applicationData.getId())){
            //新增id
            applicationData.setId(UUID.randomUUID().toString().replace("-", ""));
            result=vmApplicationDao.ApplicationSave(applicationData);
        }
        return result;
    }
    /*
    修改IP
     */
    @Override
    public int ApplicationUpdataById(ApplicationData applicationData) {
        int result = 0;
        if (!StringUtils.isEmpty(applicationData.getApplyUser())){
            result=vmApplicationDao.ApplicationUpdataById(applicationData);
            return result;
        }else {
            return result;
        }
    }
    /*
     * @Description: 删除IP
     * @param applicationData
     * @return
     * @Author: Y6
     * @Date: 2024/12/2 17:06
     */
    @Override
    public int ApplicationDelById(ApplicationData applicationData) {
        int result = 0;
        if (!StringUtils.isEmpty(applicationData.getApplyUser())){
            result=vmApplicationDao.ApplicationDelById(applicationData);
            return result;
        }else {
            return result;
        }
    }
    /*
     * @Description: ip审核提交
     * @param applicationData
     * @return00未提交01待审核02已审核03驳回04待完成（观网处填写服务器信息中）05完成（观网处填写服务器信息完成）
     * @Author: Y6
     * @Date: 2024/12/2 17:13
     */
    @Override
    public int VMApplicationSubmit(ApplicationData applicationData) {
        //TODO 还需要完善用户信息新增,目前只是单纯修改审核状态
        int result = 0;
        //修改状态为待审核01
        applicationData.setDataType("01");
        result=vmApplicationDao.VMApplicationSubmit(applicationData);
        return result;
    }
    /*
     * @Description: IP撤回
     * @param applicationData
     * @return
     * @Author: Y6
     * @Date: 2024/12/2 17:13
     */
    @Override
    public int VMApplicationWithdraw(ApplicationData applicationData) {
        //TODO: 还需要完善用户信息新增,目前只是单纯修改审核状态
        int result = 0;
        //修改状态为待审核01
        applicationData.setDataType("00");
        result=vmApplicationDao.VMApplicationWithdraw(applicationData);
        return result;
    }


}
